/**
 * Created on 2007-03-06 23:02
 */
package game;

import game.media.gfx.EntityManager;
import game.media.gfx.SquareEntity;

/**
 * @author David Wallin
 */
public final class BlockPart extends BlockComponent
{
	/**
	 * The matris in which this block part recides
	 */
	private Matris				m_Matris;
	/**
	 * Graphical representation of this block part
	 */
	private SquareEntity		m_GraphicalRepresentation;
	
	/**
	 * Constructor, initializes members
	 * 
	 * @param x X position of this BlockPart in the given matris
	 * @param y Y position of this BlockPart in the given matris
	 * @param matris The matris this block part recides in
	 * @param graphicalRepresenation the graphical represenation of this block part
	 */
	public BlockPart(int x, int y, Matris matris, SquareEntity graphicalRepresenation)
	{
		super(x, y);
		
		m_Matris = matris;
		m_GraphicalRepresentation = graphicalRepresenation;
	}
	
	public void setMatrisXpos(int matrisXpos)
	{
		super.setMatrisXpos(matrisXpos);
		
		m_GraphicalRepresentation.setXpos((matrisXpos * m_RenderManager.getSquareEntityWidth()) + m_Matris.getXpos());
	}
	
	public void setMatrisYpos(int matrisYpos)
	{
		super.setMatrisYpos(matrisYpos);
		
		m_GraphicalRepresentation.setYpos((matrisYpos * m_RenderManager.getSquareEntityHeight()) + m_Matris.getYpos());
	}
	
	public void setMatris(Matris matris)
	{
		m_Matris = matris;
	}
	
	public void setState(States state)
	{
		if(state == States.NORMAL)
		{
			m_GraphicalRepresentation.setState(m_GraphicalRepresentation.getNormalState());
		}
		
		if(state == States.HIGHLIGHTED)
		{
			m_GraphicalRepresentation.setState(m_GraphicalRepresentation.getHighlightedState());
		}
	}
	
	@Override
	public void display(boolean display)
	{
		m_GraphicalRepresentation.display(display);
	}
	
	public void remove()
	{
		super.remove();
		
		EntityManager.INSTANCE.removeEntity(m_GraphicalRepresentation);
	}
}
